package com.bigdata.booklibraryseatapi.controller;

import com.bigdata.booklibraryseatapi.common.pojo.PageResult;
import com.bigdata.booklibraryseatapi.service.IUserAppService;
import com.bigdata.booklibraryseatapi.vo.req.EditUserReqVO;
import com.bigdata.booklibraryseatapi.vo.req.LoginReqVO;
import com.bigdata.booklibraryseatapi.vo.req.PageUserReqVO;
import com.bigdata.booklibraryseatapi.vo.req.RegisterReqVO;
import com.bigdata.booklibraryseatapi.vo.resp.LoginRespVO;
import com.bigdata.booklibraryseatapi.vo.resp.PageUserRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 小程序用户表 前端控制器
 * </p>
 *
 * @author book
 * @since 2023-12-10
 */
@RestController
@RequestMapping("/api")
@Api(value = "UserAppController",tags = {"小程序用户接口"})
public class UserAppController {

    @Resource
    private IUserAppService iUserAppService;


    /**
     * 后台用户接口，不对外开放，仅提供给admin用户进行用户注册
     *
     * @param vo
     */
    @PostMapping("/admin/user/register")
    @ApiOperation(value = "注册接口")
    public void register(@RequestBody @Valid RegisterReqVO vo) {
        iUserAppService.register(vo);
    }


    /**
     * 小程序用户登录接口
     * @param vo
     * @return LoginRespVO
     */
    @PostMapping("/admin/user/login")
    @ApiOperation(value = "登录接口")
    public LoginRespVO adminLogin(@RequestBody @Valid LoginReqVO vo) {
        return iUserAppService.login(vo);
    }

    /**
     * 小程序用户登录接口
     * @param vo
     * @return LoginRespVO
     */
    @PostMapping("/uniApp/user/login")
    @ApiOperation(value = "登录接口")
    public LoginRespVO login(@RequestBody @Valid LoginReqVO vo) {
        return iUserAppService.login(vo);
    }


    /**
     * 修改小程序用户登录接口
     * @param vo
     * @return
     */
    @PostMapping("/admin/user/edit")
    @ApiOperation(value = "登录接口")
    public void editUser(@RequestBody @Valid EditUserReqVO vo) {
        iUserAppService.editUser(vo);
    }

    /**
     * 后台获取小程序用户分页数据
     * @param vo
     * @return
     */
    @PostMapping("/uniApp/user")
    @ApiOperation(value = "用户分页接口")
    public PageResult<PageUserRespVO> pageUsers(@RequestBody @Valid PageUserReqVO vo) {
        return iUserAppService.pageUsers(vo);
    }
}
